package com.qianfeng.openapi.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.openapi.mapper.RechargeMapper;
import com.qianfeng.openapi.pojo.Recharge;
import com.qianfeng.openapi.service.RechargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;


@Service
@Transactional
public class RechargeServiceImpl implements RechargeService {
    @Autowired
    private RechargeMapper rechargeMapper;
    @Override
    public void insetRecharge(Recharge recharge) {
        recharge.setCreateTime(new Date());
        recharge.setOrderId((long) IdWorker.getId());
        rechargeMapper.insetRecharge(recharge);

    }

    @Override
    public void deleteRechargeById(int[] ids) {
        rechargeMapper.deleteRechargeById(ids);
    }

    @Override
    public void updateRecharge(Recharge recharge) {
        recharge.setCreateTime(new Date());
        rechargeMapper.updateRecharge(recharge);
    }

    @Override
    public PageInfo<Recharge> getAllRecharge(int page, int limit, Recharge recharge) {
        PageHelper.startPage(page,limit);
        List<Recharge> allRecharge = rechargeMapper.getAllRecharge(recharge);
        PageInfo<Recharge> pageInfo = new PageInfo<>(allRecharge);
        return pageInfo;
    }
}
